//
//  CarDetailViewController.m
//  OneCreditTreasure
//
//  Created by iOS Grouper on 16/8/26.
//
//

#import "CarDetailViewController.h"
#import "YYCycleScrollView.h"
#import "TitleDetailTableViewCell.h"//title
#import "DetailInfoTableViewCell.h"
#import "CarDetailTableViewCell.h"
@interface CarDetailViewController ()<UITableViewDelegate,UITableViewDataSource>{
    UITableView *myTableView;
    NSMutableArray *myTitleArray;
    UIButton *applyButton;

}

@end

@implementation CarDetailViewController
- (void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"车辆详情";

    [self creatView];
    myTitleArray = [NSMutableArray arrayWithObjects:@"上牌时间",@"所在地",@"颜色",@"排量",@"变速箱", nil];
    
    
}

- (void)creatView{
    
    
    
    
    YYCycleScrollView *cycleScrollView = [[YYCycleScrollView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 170 * AUTO_HEIGHT) animationDuration:2.0];
    [self.view addSubview:cycleScrollView];
    NSMutableArray *viewArray = [[NSMutableArray alloc] init];
    for (int i = 0; i < 5; i++) {
        UIImageView *tempImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 170 * AUTO_HEIGHT)];
        
        
        tempImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",i+1]];
        tempImageView.contentMode = UIViewContentModeScaleAspectFill;
        tempImageView.clipsToBounds = true;
        [viewArray addObject:tempImageView];
        cycleScrollView.backgroundColor = [UIColor redColor];
    }
    
    [cycleScrollView setFetchContentViewAtIndex:^UIView *(NSInteger(pageIndex)) {
        return [viewArray objectAtIndex:pageIndex];
    }];
    [cycleScrollView setTotalPagesCount:^NSInteger{
        return 5;
    }];
    [cycleScrollView setTapActionBlock:^(NSInteger(pageIndex)) {
        
        NSLog(@"点击的相关的页面%ld",(long)pageIndex);
        
    }];
    
    
    
    myTableView = [UITableView new];
    [self.view addSubview:myTableView];
    [myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(cycleScrollView.mas_bottom);
        make.left.mas_equalTo(self.view);
        make.width.mas_equalTo(kScreenW);
        make.height.mas_equalTo(kScreenH);
        
    }];
    myTableView.backgroundColor = LV;
    myTableView.delegate = self;
    myTableView.dataSource = self;
    [myTableView registerClass:[TitleDetailTableViewCell class] forCellReuseIdentifier:@"TitleDetailTableViewCell"];
    [myTableView registerClass:[DetailInfoTableViewCell class] forCellReuseIdentifier:@"DetailInfoTableViewCell"];
    [myTableView registerClass:[CarDetailTableViewCell class] forCellReuseIdentifier:@"CarDetailTableViewCell"];
    
    
    
    
    
    applyButton = [UIButton new];
    [self.view addSubview:applyButton];
    [applyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.view);
        make.height.mas_equalTo(50 * AUTO_HEIGHT);
        make.left.mas_equalTo(0);
        make.centerXWithinMargins.mas_equalTo(self.view);
        
    }];
    applyButton.backgroundColor = [UIColor whiteColor];
    applyButton.titleLabel.font = [UIFont fontWithName:ZIXING size:14 ];
    [applyButton setTitleColor:HS forState:UIControlStateNormal];
    [applyButton setTitle:@"立即申请" forState:UIControlStateNormal];
    
    
    UIView *line = [UIView new];
    [applyButton addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(applyButton.mas_top);
        make.height.mas_equalTo(0.4);
        make.width.mas_equalTo(kScreenW);
        
        
    }];
    line.backgroundColor = HS;
    

    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0 && indexPath.section == 0) {
        TitleDetailTableViewCell *titleCell = [tableView dequeueReusableCellWithIdentifier:@"TitleDetailTableViewCell"];
       
        return titleCell;
    }
    if (indexPath.section == 1) {
        CarDetailTableViewCell *craCell = [tableView dequeueReusableCellWithIdentifier:@"CarDetailTableViewCell"];
        return craCell;
    }
    else{
    DetailInfoTableViewCell *textCell = [tableView dequeueReusableCellWithIdentifier:@"DetailInfoTableViewCell"];
    textCell.textLabel.text = myTitleArray[indexPath.row- 1];
        textCell.textLabel.font = [UIFont fontWithName:ZIXING size:TEXTLABELFONT];
        textCell.textLabel.textColor = HS;
        textCell.infoLB.text = @"1234";
        textCell.infoLB.textColor = HS;
    return textCell;
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 1) {
        return 1;
    }
    else{
    return myTitleArray.count + 1;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0 && indexPath.section == 0) {
        return 60 * AUTO_HEIGHT;
    }
    if (indexPath.section == 1) {
        return 120 * AUTO_HEIGHT;
    }
    else{
        return tableView.rowHeight;
    }
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10 * AUTO_HEIGHT;
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
